//
//  PredictVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/27.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "PredictVC.h"
#import "CommentsCell.h"
#import "CommentsTextView.h"
#import "InformationCell.h"
#import "MasterCell.h"
#import "NewsContentCell.h"
#import "InformationVM.h"
#import "NewsShareCell.h"
#import "InformationLeftImageCell.h"
#import "InformationImageCell.h"
#import "CommentDetailVC.h"
#import "CommentListVC.h"
#import "OtherInfoVC.h"
#import "ImageTableViewCell.h"
#import "NOCommentCell.h"
#import "HomePageVM.h"

@interface PredictVC ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic ,strong) UITableView   *tableView;
//@property (nonatomic ,strong) UIView        *bottomView;
//@property (nonatomic ,strong) CommentsTextView *cTextView;
@property (nonatomic ,strong) NewsContentModel *contentModel;
@property (nonatomic ,strong) NSMutableArray   *newsArr;
///精彩评论
@property (nonatomic ,strong) NSMutableArray *goodComments;
/////评论列表
@property (nonatomic ,strong) NSArray *advertisingArr;
@property (nonatomic ,strong) NSMutableArray *commentsImages;

@property (nonatomic ,strong) AdvertisingModel *contentAdvertisingModel;
@end

@implementation PredictVC{
    RITLPhotoNavigationViewModel * viewModel;
    NSString       *sendStr;
    NSString       *selectModelId;
    NSMutableArray *arr1;
    NSMutableArray *arr2;
    NSMutableArray *arr3;
    NSMutableArray *arr4;
    NSMutableArray *arr5;
    NSMutableArray *arr6;
    
    
}

-(void)receiveNotification{
    
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"TG_ReloadData" object:nil];
    viewModel = [RITLPhotoNavigationViewModel new];
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(onclickNav)];
    self.navigationItem.rightBarButtonItem=rightItem;
}

//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//}
//
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
//}

- (void)backClick{
    [self.navigationController popToViewController:self.saveViewController animated:YES];
}

#pragma mark - 跳转到其他新闻页面
- (void)jumpOtherNews:(NewsModel *)model{
    PredictVC   *vc=[[PredictVC alloc]init];
    vc.model=model;
    vc.title=self.title;
    vc.LTypeName=self.LTypeName;
    vc.saveViewController=self.saveViewController;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setTypeId:(NSString *)typeId{
    _typeId=typeId;
    WS(weakSelf);
    [[HomePageVM manage] getNewsInfoWithId:typeId andSuccess:^(id returnValue) {
        NewsLottryTypeModel *nModel=returnValue;
        weakSelf.title=[NSString stringWithFormat:@"%@.%@",nModel.LTypeName,nModel.TypeName];
        weakSelf.LTypeName=nModel.LTypeName;
    } andFail:^(NSString *errorMessage, NSError *error) {
        weakSelf.title=@"精彩资讯";
    }];
}

#pragma mark -- 获取新闻内容详情
- (void)getNewsContentDetail{
    WS(weakSelf);
    [[InformationVM manage] getNewsDetailWithId:self.model.Id Success:^(id returnValue) {
        weakSelf.contentModel=returnValue;
        weakSelf.contentModel.adModel=weakSelf.contentAdvertisingModel;
//        [weakSelf.tableView reloadData];
        
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [weakSelf getRecommendNewsList];

        });
//        [weakSelf getWonderfulComment];
        //        [weakSelf getComments];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}


- (void)setModel:(NewsModel *)model{
    _model=model;
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [self getContentAdvertising];
    });
    
}



#pragma mark -- 获取推荐阅读
- (void)getRecommendNewsList{
    WS(weakSelf);
    [[InformationVM manage] getRecommendNewsListWithId:self.model.TypeId Success:^(id returnValue) {
        weakSelf.newsArr=returnValue;
        
//        [weakSelf.tableView reloadData];
        
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [weakSelf getAdvertising];
        });
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}
//
//#pragma mark -- 获取精彩评论
//- (void)getWonderfulComment{
//    WS(weakSelf);
//    [[CommentVM manage] getWonderfulCommentId:self.model.Id andType:2 andCount:3 Success:^(id returnValue) {
//        weakSelf.goodComments=returnValue;
//        [weakSelf.tableView reloadData];
//
//    } andFail:^(NSString *errorMessage, NSError *error) {
//
//    }];
//}

#pragma mark -- 获取广告
- (void)getAdvertising{
    WS(weakSelf);
    [[InformationVM manage] getAdvertWithLocation:self.model.TypeId andType:2 Success:^(id returnValue) {
        weakSelf.advertisingArr=returnValue;
//        for (AdvertisingModel *model in self.advertisingArr) {
//            NSLog(@"%@---%ld",model.Title,model.Layer);
//        }
        [weakSelf insertAdvertising];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

#pragma mark -- 获取文章里面的广告
- (void)getContentAdvertising{
    WS(weakSelf);
    
    
    NSLog(@"-->%@",self.model.TypeId);
    [[InformationVM manage] getAdvertWithLocation:self.model.TypeId andType:5 Success:^(id returnValue) {
        NSArray *arr=returnValue;
        if (arr.count>0) {
            weakSelf.contentAdvertisingModel=arr.lastObject;
        }
        
        
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [weakSelf getNewsContentDetail];
        });
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}


#pragma mark -- 插入广告
- (void)insertAdvertising{
    arr1=[[NSMutableArray alloc]init];
    arr2=[[NSMutableArray alloc]init];
    arr3=[[NSMutableArray alloc]init];
    arr4=[[NSMutableArray alloc]init];
    arr5=[[NSMutableArray alloc]init];
    arr6=[[NSMutableArray alloc]init];
    for (AdvertisingModel *model in self.advertisingArr) {
        if (model.Display) {
            if (model.Layer==1) {
                [arr1 addObject:model];
            }else if (model.Layer==2){
                [arr2 addObject:model];
            }else if (model.Layer==3){
                [arr3 addObject:model];
            }else if (model.Layer==4){
                [arr4 addObject:model];
            }else if (model.Layer==5){
                [arr5 addObject:model];
            }else if (model.Layer==6){
                [arr6 addObject:model];
            }
        }
    }
    [self.newsArr addObjectsFromArray:arr6];
    [self.tableView reloadData];
}


//#pragma mark -- 发布评论
//- (void)publishComment{
//    WS(weakSelf);
//    [SVProgressHUD show];
//    [self postImageWithDoneArr:[NSMutableArray new] done:^(NSMutableArray *arr) {
//
//        if (selectModelId) {
//            [[CommentVM manage] publishWithId:selectModelId andType:2 andContent:[[SocketRocketUtility instance] sendMessageConversion:self.cTextView.textView.text] andCommentType:2 andPic:arr Success:^(id returnValue) {
//                [weakSelf.commentsImages removeAllObjects];
//                [weakSelf addRepaly];
//                sendStr=nil;
//                selectModelId=nil;
//                [weakSelf.cTextView removeSelf];
//                [SVProgressHUD dismiss];
//            } andFail:^(NSString *errorMessage, NSError *error) {
//
//            }];
//        }else{
//            [[CommentVM manage] publishWithId:self.model.Id andType:2 andContent:[[SocketRocketUtility instance] sendMessageConversion:self.cTextView.textView.text] andCommentType:1 andPic:arr Success:^(id returnValue) {
//                [weakSelf.commentsImages removeAllObjects];
//                sendStr=nil;
//                if (returnValue) {
//                    if (weakSelf.goodComments.count<3) {
//                        [weakSelf.goodComments addObject:returnValue];
//                        [weakSelf.tableView reloadData];
//                    }
//
//                }
//                selectModelId=nil;
//                [weakSelf.cTextView removeSelf];
//                [SVProgressHUD dismiss];
//            } andFail:^(NSString *errorMessage, NSError *error) {
//
//            }];
//        }
//
//
//    }];
//
//}
//
//- (void)addRepaly{
//    for (CommentModel *cModel in _goodComments) {
//        if ([cModel.Id isEqualToString:selectModelId]) {
//            cModel.ReplayCount+=1;
//        }
//    }
//    [self.tableView reloadData];
//}
//
//- (void)postImageWithDoneArr:(NSMutableArray *)doneArr done:(void(^)(NSMutableArray *arr))doneBlock{
//    if (doneArr.count==self.commentsImages.count) {
//        doneBlock(doneArr);
//        return;
//    }
//    WS(weakSelf);
//    [[BaseVM manage] postImageWithImage:self.commentsImages[doneArr.count] andType:3 andSuccess:^(id returnValue) {
//        [doneArr addObject:[returnValue objectForKey:@"ResouceId"]];
//        [weakSelf postImageWithDoneArr:doneArr done:doneBlock];
//    } andFail:^(NSString *errorMessage, NSError *error) {
//
//    }];
//}
//
//#pragma mark -- 对评论进行回复
//- (void)replayComment:(CommentModel *)model{
//    selectModelId=[model.Id copy];
//    [self.cTextView.textView becomeFirstResponder];
//}
//
//#pragma mark -- 对评论进行点赞
//- (void)likeComment:(CommentModel *)model{
//    self.tableView.userInteractionEnabled=NO;
//    WS(weakSelf);
//    [[CommentVM manage] clickLikeWithId:model.Id andType:2 andOperationType:model.IsLike?2:1 Success:^(id returnValue) {
//        [weakSelf refreshPraise:model];
//    } andFail:^(NSString *errorMessage, NSError *error) {
//        weakSelf.tableView.userInteractionEnabled=YES;
//    }];
//}
//
//- (void)refreshPraise:(CommentModel *)model{
//    BOOL isLike=!model.IsLike;
//    for (CommentModel *cModel in _goodComments) {
//        if ([cModel.Id isEqualToString:model.Id]) {
//            cModel.IsLike=isLike;
//            if (cModel.IsLike) {
//                cModel.StarCount+=1;
//            }else{
//                cModel.StarCount-=1;
//            }
//        }
//    }
//    self.tableView.userInteractionEnabled=YES;
//    [self.tableView reloadData];
//}
//
//#pragma mark -- 查看更多回复
//- (void)lookMoreReplay:(CommentModel *)model{
//    CommentDetailVC *vc=[[CommentDetailVC alloc] init];
//    vc.type=CommentListTypeDefault;
//    vc.model=model;
//
//    [self.navigationController pushViewController:vc animated:YES];
//}
//
//#pragma mark -- 查看全部评论
//- (void)onclickCommentsList{
//    CommentListVC *vc=[[CommentListVC alloc]init];
//    vc.ID=self.model.Id;
//    [self.navigationController pushViewController:vc animated:YES];
//}
//
//#pragma mark -- 选择照片
//- (void)selectPic{
//
//    if (self.commentsImages.count>2) {
//        [SVProgressHUD showErrorWithStatus:@"最多只能上传3张图片"];
//        return;
//    }
//
//    sendStr=self.cTextView.textView.text;
//    [self.cTextView removeSelf];
//    UIAlertController *alertCtrl=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//    UIAlertAction *albumAction=[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        WS(weakSelf);
//        viewModel.RITLBridgeGetImageBlock = ^(NSArray  * images){
//            for (NSDictionary *dict in images) {
//                [weakSelf.commentsImages addObject:[dict objectForKey:@"image"]];
//            }
//            [weakSelf.cTextView.textView becomeFirstResponder];
//        };
//        self.hidesBottomBarWhenPushed = NO;
//        viewModel.maxNumberOfSelectedPhoto=3-self.commentsImages.count;
//        RITLPhotoNavigationViewController * viewController = [RITLPhotoNavigationViewController photosViewModelInstance:viewModel];
//        [self presentViewController:viewController animated:true completion:^{}];
//    }];
//    UIAlertAction *cameraAction=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
//        UIImagePickerController * ipc = [[UIImagePickerController alloc] init];
//        ipc.delegate = self;
//        ipc.sourceType = sourceType;
//        [self presentViewController:ipc animated:YES completion:nil];
//    }];
//    [alertCtrl addAction:cancleAction];
//    [alertCtrl addAction:albumAction];
//    [alertCtrl addAction:cameraAction];
//    [self presentViewController:alertCtrl animated:YES completion:nil];
//}

- (void)onclickShare{
    
}

#pragma mark -- 查看评论数
- (void)lookComments{
    
}

//#pragma mark - tableView输入框遮挡
//- (void)keyboardWillShow:(NSNotification *)notification {
//    NSDictionary *userInfo = [notification userInfo];
//    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
//    CGRect keyboardRect = [aValue CGRectValue];
//    keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
//    CGFloat keyboardTop = keyboardRect.origin.y;
//    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
//    NSTimeInterval animationDuration;
//    [animationDurationValue getValue:&animationDuration];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:animationDuration];
//    [self.cTextView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(@(keyboardTop+(SCREEN_WIDTH-60)/6+10+HEIGHT_CHATBOXVIEW-(self.cTextView.imageArr.count>0?(SCREEN_WIDTH-60)/6+5:0)));
//    }];
//    [UIView commitAnimations];
//}
//
//- (void)keyboardWillHide:(NSNotification *)notification {
//    NSDictionary* userInfo = [notification userInfo];
//    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
//    NSTimeInterval animationDuration;
//    [animationDurationValue getValue:&animationDuration];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:animationDuration];
//    [self.cTextView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(@(SCREEN_HEIGHT+(self.cTextView.imageArr.count>0?(SCREEN_WIDTH-60)/6:0)));
//    }];
//    [UIView commitAnimations];
//
//}



#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else if (section==1){
        return 1;
    }
    else if (section==2){
        return self.newsArr.count;
    }else if (section==3){
        return 0;
    }else if (section==4){
        return self.goodComments.count>0?self.goodComments.count:1;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        NewsContentCell *cell=[tableView dequeueReusableCellWithIdentifier:@"NewsContentCell" forIndexPath:indexPath];
        cell.arr1=arr1;
        cell.arr2=arr2;
        cell.arr3=arr3;
        [cell setContent:self.contentModel];

        return cell;
    }else if (indexPath.section==1){
        WS(weakSelf);
        NewsShareCell *cell=[tableView dequeueReusableCellWithIdentifier:@"NewsShareCell" forIndexPath:indexPath];
        cell.arr4=arr4;
        cell.arr5=arr5;
        cell.title=self.model.Title;
        [cell setPrevious:self.contentModel.Previous andNext:self.contentModel.Next];
        cell.otherBlock = ^(OtherNewsModel *model) {
            NewsModel *nModel=[[NewsModel alloc]init];
            nModel.Id=model.Id;
            nModel.Title=model.Title;
            nModel.TypeId=weakSelf.model.TypeId;
            [weakSelf jumpOtherNews:nModel];
        };
        cell.contentModel=self.contentModel;
        return cell;
    }
    else if (indexPath.section==2) {
        if ([self.newsArr[indexPath.row] isKindOfClass:[NewsModel class]]) {
            NewsModel *model=self.newsArr[indexPath.row];
            if (model.ThumbStyle==0) {
                InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell" forIndexPath:indexPath];
                [cell setModel:model];
                return cell;
            }else if (model.ThumbStyle==1){
                InformationLeftImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationLeftImageCell" forIndexPath:indexPath];
                [cell setModel:model];
                return cell;
            }else{
                InformationImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationImageCell" forIndexPath:indexPath];
                [cell setModel:model];
                return cell;
            }
        }else{
            AdvertisingModel *model=self.newsArr[indexPath.row];
            if (model.ThumbStyle==0) {
                InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell" forIndexPath:indexPath];
                [cell setAdModel:model];
                return cell;
            }else if (model.ThumbStyle==1){
                InformationLeftImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationLeftImageCell" forIndexPath:indexPath];
                [cell setAdModel:model];
                return cell;
            }else if (model.ThumbStyle==4){
                ImageTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ImageTableViewCell" forIndexPath:indexPath];
                if (model.ThumbList.count>0) {
                    [cell.imageV sd_setImageWithURL:model.ThumbList[0] placeholderImage:[UIImage imageNamed:@"big_loding"]];
                }else{
                    cell.imageV.image=[UIImage imageNamed:@"big_loding"];
                }
                
                return cell;
            }else{
                InformationImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationImageCell" forIndexPath:indexPath];
                [cell setAdModel:model];
                return cell;
            }
        }
    }else if (indexPath.section==3){
        MasterCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MasterCell" forIndexPath:indexPath];
        return cell;
    }
    
    if (self.goodComments.count>indexPath.row) {
        CommentModel *model=self.goodComments[indexPath.row];
//        WS(weakSelf);
        if (model.ReplayCount>0) {
            CommentsCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CommentsCell" forIndexPath:indexPath];
//            [cell setModel:model];
//            cell.lookComment = ^(CommentModel *model) {
//                [weakSelf lookMoreReplay:model];
//            };
//            cell.likeComment = ^(CommentModel *model) {
//                [weakSelf likeComment:model];
//            };
//            cell.replayComment = ^(CommentModel *model) {
//                [weakSelf replayComment:model];
//            };
//            cell.lookUser = ^(CommentModel *model) {
////                OtherInfoVC *vc=[[OtherInfoVC alloc]init];
////                vc.userId=model.ParentComment.UserId;
////                [weakSelf.navigationController pushViewController:vc animated:YES];
//            };
            return cell;
        }
        CommentsCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CommentsCell1" forIndexPath:indexPath];
        [cell setModel:model];
//        cell.lookComment = ^(CommentModel *model) {
//            [weakSelf lookMoreReplay:model];
//        };
//        cell.likeComment = ^(CommentModel *model) {
//            [weakSelf likeComment:model];
//        };
//        cell.replayComment = ^(CommentModel *model) {
//            [weakSelf replayComment:model];
//        };
//        cell.lookUser = ^(CommentModel *model) {
////            OtherInfoVC *vc=[[OtherInfoVC alloc]init];
////            vc.userId=model.ParentComment.UserId;
////            [weakSelf.navigationController pushViewController:vc animated:YES];
//        };
        return cell;
    }else{
        NOCommentCell *cell=[tableView dequeueReusableCellWithIdentifier:@"NOCommentCell" forIndexPath:indexPath];
        return cell;
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==2) {
        if (self.newsArr.count == 0) {
            return 0;
        }else{
            return 35;
        }
    }else if (section==3){
        return 0;
    }else if (section==4){
        return 40;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==2) {
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
        view.backgroundColor=DEFAULTBGCOLOR;
        QXLable *lab=[[QXLable alloc]initWithFount:15];
        lab.text=@"推荐阅读";
        [lab setFrame:CGRectMake(10, 0, 200, 35)];
        [view addSubview:lab];
        return view;
    }else if (section==3){
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        view.backgroundColor=[UIColor whiteColor];
        QXLable *lab=[[QXLable alloc]initTitle];
        lab.text=[NSString stringWithFormat:@"%@竞猜红人",self.LTypeName];
        [lab setFrame:CGRectMake(10, 5, 200, 35)];
        [view addSubview:lab];
        
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5)];
        line.backgroundColor=DEFAULTBGCOLOR;
        [view addSubview:line];
        return view;
    }else if (section==4){
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        view.backgroundColor=[UIColor whiteColor];
        QXLable *lab=[[QXLable alloc]initTitle];
        lab.text=@"精彩评论";
        [lab setFrame:CGRectMake(10, 5, 200, 35)];
        [view addSubview:lab];
        
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5)];
        line.backgroundColor=DEFAULTBGCOLOR;
        [view addSubview:line];
        
        if (self.goodComments.count==3) {
            UIButton *btnMore=[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-100, 5, 100, 35)];
            [btnMore setTitle:@"更多评论>>" forState:UIControlStateNormal];
            [btnMore.titleLabel setFont:[UIFont systemFontOfSize:15]];
            [btnMore setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
//            [btnMore addTarget:self action:@selector(onclickCommentsList) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:btnMore];
        }
        
        
        return view;
    }else if (section==5){
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        view.backgroundColor=[UIColor whiteColor];
        QXLable *lab=[[QXLable alloc]initTitle];
        lab.text=@"最新评论(30)";
        [lab setFrame:CGRectMake(10, 5, 200, 35)];
        [view addSubview:lab];
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5)];
        line.backgroundColor=DEFAULTBGCOLOR;
        [view addSubview:line];
        return view;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==2) {
        if ([self.newsArr[indexPath.row] isKindOfClass:[NewsModel class]]) {
            NewsModel *model=self.newsArr[indexPath.row];
            [self jumpOtherNews:model];
        }else{
            
            
            AdvertisingModel *model=self.newsArr[indexPath.row];
        
            if ([model.Title containsString:@"】"]) {
                
                UIPasteboard *copy = [UIPasteboard generalPasteboard];
                NSRange startRange = [model.Title rangeOfString:@"【"];
                NSRange endRange = [model.Title rangeOfString:@"】"];
                NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
                NSString *result = [model.Title substringWithRange:range];
                
                [copy setString:result];
                
                [SVProgressHUD showSuccessWithStatus:@"复制成功"];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                    [[UIApplication sharedApplication]openURL:[NSURL URLWithString: @"weixin://"]];
                });
                
            }else{
                
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString: model.TransferUrl]];

                PublicWebVC *vc=[[PublicWebVC alloc]init];
                vc.url=model.TransferUrl;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
        
    }
}


//- (void)onclickText{
//    selectModelId=nil;
//    [self.cTextView.textView becomeFirstResponder];
//}
//
//
//#pragma mark -- UINavigationControllerDelegate, UIImagePickerControllerDelegate
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
//{
//    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//    [self.commentsImages addObject:image];
//    [self dismissViewControllerAnimated:YES completion:^{
//        [self.cTextView.textView becomeFirstResponder];
//    }];
//    
//    
//}

#pragma mark -- 懒加载
- (NSMutableArray *)commentsImages{
    if (!_commentsImages) {
        _commentsImages=[[NSMutableArray alloc]init];
    }
    return _commentsImages;
}


- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.backgroundColor=DEFAULTBGCOLOR;
        [_tableView registerClass:[CommentsCell class] forCellReuseIdentifier:@"CommentsCell"];
        [_tableView registerClass:[CommentsCell class] forCellReuseIdentifier:@"CommentsCell1"];
        [_tableView registerClass:[InformationCell class] forCellReuseIdentifier:@"InformationCell"];
        [_tableView registerClass:[MasterCell class] forCellReuseIdentifier:@"MasterCell"];
        [_tableView registerClass:[NewsContentCell class] forCellReuseIdentifier:@"NewsContentCell"];
        [_tableView registerClass:[NewsShareCell class] forCellReuseIdentifier:@"NewsShareCell"];
        [_tableView registerClass:[InformationLeftImageCell class] forCellReuseIdentifier:@"InformationLeftImageCell"];
        [_tableView registerClass:[InformationImageCell class] forCellReuseIdentifier:@"InformationImageCell"];
        [_tableView registerClass:[NOCommentCell class] forCellReuseIdentifier:@"NOCommentCell"];
        _tableView.estimatedRowHeight=400;
        _tableView.rowHeight=UITableViewAutomaticDimension;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.view);
            make.top.bottom.equalTo(weakSelf.view);
        }];
    }
    return _tableView;
}

//- (CommentsTextView *)cTextView{
//    if (!_cTextView) {
//        WS(weakSelf);
//        _cTextView=[[CommentsTextView alloc]init];
//        _cTextView.textView.text=sendStr;
//        [_cTextView setImageArr:self.commentsImages];
//        _cTextView.clickEmj = ^(BOOL isFace) {
//            if (isFace) {
//                [weakSelf.cTextView.textView resignFirstResponder];
//                [weakSelf.cTextView mas_updateConstraints:^(MASConstraintMaker *make) {
//                    make.height.mas_equalTo(@(SCREEN_HEIGHT+(self.cTextView.imageArr.count>0?(SCREEN_WIDTH-60)/6:0)));
//                }];
//            }else{
//                [weakSelf.cTextView.textView becomeFirstResponder];
//            }
//        };
//        _cTextView.showPic = ^ {
//            [weakSelf selectPic];
//        };
//
//        _cTextView.sendBlock = ^{
//            [weakSelf publishComment];
//
//        };
//        _cTextView.removeBlock = ^{
//            [weakSelf.cTextView removeFromSuperview];
//            weakSelf.cTextView=nil;
//        };
//        [self.view addSubview:_cTextView];
//
//        [_cTextView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.top.equalTo(self.view);
//            make.height.mas_equalTo(@0);
//        }];
//
//
//
//    }
//    return _cTextView;
//}

//- (UIView *)bottomView{
//    if (!_bottomView) {
//        _bottomView=[[UIView alloc]init];
//        _bottomView.backgroundColor=[UIColor whiteColor];
//        UIView *line=[[UIView alloc]init];
//        line.backgroundColor=DEFAULTBGCOLOR;
//        [_bottomView addSubview:line];
//        [line mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.top.equalTo(_bottomView);
//            make.height.mas_equalTo(@.7);
//        }];
//
//
//        UIButton  *btnReply=[[UIButton alloc]init];
//        [btnReply setImage:[UIImage imageNamed:@"comments_count"] forState:UIControlStateNormal];
//        [btnReply addTarget:self action:@selector(onclickCommentsList) forControlEvents:UIControlEventTouchUpInside];
//        [_bottomView addSubview:btnReply];
//        [btnReply mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.right.bottom.equalTo(_bottomView);
//            make.width.mas_equalTo(@47);
//        }];
//
//        QXLable *labCount=[[QXLable alloc]initWithFount:10];
//        labCount.textAlignment=NSTextAlignmentCenter;
//        labCount.textColor=NAVCOLOR;
//        labCount.text=self.contentModel.CommentCount;
//        [_bottomView addSubview:labCount];
//        [labCount mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.equalTo(btnReply).with.offset(8);
//            make.centerY.equalTo(btnReply).with.offset(-8);
//        }];
//
//        UIButton *btnText=[[UIButton alloc]init];
//        [btnText addTarget:self action:@selector(onclickText) forControlEvents:UIControlEventTouchUpInside];
//        btnText.backgroundColor=DEFAULTBGCOLOR;
//        btnText.layer.masksToBounds=YES;
//        btnText.layer.cornerRadius=4.0;
//        [_bottomView addSubview:btnText];
//        [btnText mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.edges.equalTo(_bottomView).with.insets(UIEdgeInsetsMake(5, 10, 5, 47));
//        }];
//
//
//        [self.view addSubview:_bottomView];
//        [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.bottom.equalTo(self.view);
//            make.height.mas_equalTo(@50);
//        }];
//    }
//    return _bottomView;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)setNewsType:(NSString *)newsType{

    _newsType = newsType;
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [self getNewsTypeWithId:newsType];
    });
    
    
    
}

-(void)getNewsTypeWithId:(NSString *)newsType{
    
    NSLog(@"%@",newsType);
    
  
    [[InformationVM manage] getNewsTypeWithID:newsType Success:^(id returnValue) {
        
        
        self.title = [NSString stringWithFormat:@"%@.%@",returnValue[@"LTypeName"],returnValue[@"TypeName"]];
        
        
        self.LTypeName = returnValue[@"LTypeName"];
        
    } Fail:^(NSString *errorMessage, NSError *error) {
        
    }];
    

    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)dealloc{
    
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"TG_ReloadData" object:self];
    
}

@end
